home *** CD-ROM | disk | FTP | other *** search
- #pragma once
- /*****
- *
- * Grant's CGI Framework (Common Grant Interface :-)
- * http://arpp.carleton.ca/grant/mac/grantscgi/
- *
- * CGI.h
- *
- * standard types and function prototypes for cgi applications
- * See the Read Me or CGI.c for instructions on using the CGI Utilities
- *
- * #include this file in your source files that need to access the cgi module
- *
- * This is a support file for "Grant's CGI Framework".
- * Please see the license agreement that accompanies the distribution package
- * for licensing details.
- *
- * Copyright ©1995,1996 by Grant Neufeld
- *
- * http://arpp.carleton.ca/grant/
- * gneufeld@ccs.carleton.ca
- * grant@acm.org
- *
- *****/
-
- #include "MyConfiguration.h"
- #if kCompileWithCGICode
-
- #include <Threads.h>
-
- /*** CONSTANT DECLARATIONS ***/
-
- #define kCGIParamMaxSize 32769
-
- #define kCGIHTTPMethodGet "GET"
- #define kCGIHTTPMethodPost "POST"
- #define kCGIHTTPMethodGetConditional "GET_CONDITIONAL"
-
- #define kCGIFormFieldDelimiter '='
- #define kCGIFormFieldSeparator '&'
-
- /* Apple events */
-
- #define kAEClassCGI 'WWWΩ'
- #define kAEIDSearchDoc 'sdoc'
-
- /* CGI event parameters */
- #define kCGIpath_args '----'
- #define kCGIhttp_search_args 'kfor'
- #define kCGIusername 'user'
- #define kCGIpassword 'pass'
- #define kCGIfrom_user 'frmu'
- #define kCGIclient_address 'addr'
- #define kCGIpost_args 'post'
- #define kCGImethod 'meth'
- #define kCGIserver_name 'svnm'
- #define kCGIserver_port 'svpt'
- #define kCGIscript_name 'scnm'
- #define kCGIcontent_type 'ctyp'
- #define kCGIreferer 'refr'
- #define kCGIuser_agent 'Agnt'
- #define kCGIaction 'Kact'
- #define kCGIaction_path 'Kapt'
- #define kCGIclient_ip 'Kcip'
- #define kCGIfull_request 'Kfrq'
- #define kCGIversion 'Pvrs'
- #define kCGIconnection 'Kcid'
-
- /* for an official listing of the maximum sizes for CGI parameters,
- <http://www.biap.com/datapig/mrwheat/cgi_params.html> */
- #define kCGIMaxpath_args 1024
- #define kCGIMaxhttp_search_args 1024
- #define kCGIMaxusername 32
- #define kCGIMaxpassword 32
- #define kCGIMaxfrom_user 128
- #define kCGIMaxclient_address 256
- #define kCGIMaxpost_args 32768
- #define kCGIMaxmethod 32
- #define kCGIMaxserver_name 256 /* server address? */
- #define kCGIMaxserver_port 16
- #define kCGIMaxscript_name 1024
- #define kCGIMaxcontent_type 64
- #define kCGIMaxreferer 1024
- #define kCGIMaxuser_agent 256
- #define kCGIMaxaction 32
- #define kCGIMaxaction_path 1024
- #define kCGIMaxclient_ip 32
- #define kCGIMaxfull_request 4096
- //• this isn't actually a parameter of the CGI event
- //#define kCGIMaxversion 32768 /* ••• missing the correct value */
- #define kCGIMaxconnection 4
-
- /* Action Names */
- #define kCGIActionNameCGI "CGI"
- #define kCGIActionNameACGI "ACGI"
-
- /* Send Partial event */
- #define kMyAESendPartial 'SPar'
-
- #define kCGIPartialData '----'
- #define kConnectionIDKeyword 'Kcid'
- #define kMoreKeyword 'Kmor'
-
- #define kCGIPartialStartString "<SEND_PARTIAL>"
-
-
- /*** TYPE DECLARATIONS ***/
-
- #if kCompileWithCGIFormHandling
- typedef struct
- {
- char * name;
- char * value;
- } CGIFormField;
- #endif
-
- #if kCompileWithCGImethod
- typedef enum
- {
- HTTP_UNDEFINED,
- HTTP_get,
- HTTP_post,
- HTTP_getConditional
- } HTTPMethod;
- #endif
-
- typedef struct
- {
- /** the following fields should be treated as public read-only **/
-
- #if kCompileWithCGIpath_args
- char * path_args; /* '----' path_args */
- #endif
- #if kCompileWithCGIhttp_search_args
- char * http_search_args; /* 'kfor' http_search_args */
- #endif
- #if kCompileWithCGIusername
- char username[kCGIMaxusername]; /* 'user' username */
- #endif
- #if kCompileWithCGIpassword
- char password[kCGIMaxpassword]; /* 'pass' password */
- #endif
- #if kCompileWithCGIfrom_user
- char from_user[kCGIMaxfrom_user];/* 'frmu' from_user */
- #endif
- #if kCompileWithCGIclient_address
- char client_address[kCGIMaxclient_address];/* 'addr' client_address */
- #endif
- #if kCompileWithCGIpost_args
- char * post_args; /* 'post' post_args */
- #endif
- #if kCompileWithCGImethod
- HTTPMethod method; /* 'meth' method */
- #endif
- #if kCompileWithCGIserver_name
- char server_name[kCGIMaxserver_name];/* 'svnm' server_name */
- #endif
- #if kCompileWithCGIserver_port
- short server_port; /* 'svpt' server_port */
- #endif
- #if kCompileWithCGIscript_name
- char * script_name; /* 'scnm' script_name */
- #endif
- #if kCompileWithCGIcontent_type
- char content_type[kCGIMaxcontent_type];/* 'ctyp' content_type */
- #endif
- #if kCompileWithCGIreferer
- char * referer; /* 'refr' referer */
- #endif
- #if kCompileWithCGIuser_agent
- char user_agent[kCGIMaxuser_agent];/* 'Agnt' user_agent */
- #endif
-
- #if kCompileWithCGIActionSupport
- char action[kCGIMaxaction]; /* 'Kact' action */
- char * action_path; /* 'Kapt' action_path */
- #endif
-
- #if kCompileWithCGIclient_ip
- char client_ip[kCGIMaxclient_ip]; /* 'Kcip' client_ip */
- #endif
- #if kCompileWithCGIfull_request
- char * full_request; /* 'Kfrq' full_request */
- #endif
- //• this isn't actually a parameter of the CGI event
- // #if kCompileWithCGIversion
- // char * version; /* 'Pvrs' version */
- // #endif
-
- #if kCompileWithCGISendPartial
- long connection; /* 'Kcid' connection */
- #endif
-
- #if kCompileWithCGIFormHandling
- CGIFormField * formFields; /* the fields from form submission */
- long totalFields; /* total number of fields */
- #endif
-
- /** private fields that probably should not be touched outside
- of the CGI.c file **/
- AppleEvent appleEvent; /* originating appleEvent */
- AppleEvent replyEvent; /* apple event reply record */
-
- #if kCompileWithThreadedAppleEvents
- Boolean suspended; /* whether the AE has been suspended */
- #endif
-
- // #if kCompileWithThreadedAppleEvents
- // ThreadID thread; /* ID of the CGI handle's thread */
- // #endif
-
- /** public fields to be filled in **/
- #if kCompileWithCGIResponseDataAsHandle
- Handle responseData; /* data to return to the client */
- #else
- char * responseData; /* data to return to the client */
- #endif
- long responseSize; /* size in bytes of the response */
-
- #if kCompileWithCGIRefCon
- long refCon; /* field for storing custom data */
- #endif
- } CGIrecord;
-
- typedef CGIrecord ** CGIHdl;
-
-
- /*** GLOBAL DECLARATIONS ***/
-
- #ifdef __CGISegment__
- #define _GLOBAL_
- #else
- #define _GLOBAL_ extern
- #endif
-
- /* these are globals for holding the standard http headers.
- One of the headers must be prepended to the data returned in the Apple Event */
-
- _GLOBAL_ Str255 gHTTPHeaderOK; /* use data returned after header */
- _GLOBAL_ Str255 gHTTPHeaderRedirect; /* redirect client to different url */
- _GLOBAL_ Str255 gHTTPHeaderErr; /* an application level error */
- #if kCompileWithCGISendPartial
- _GLOBAL_ Str255 gHTTPHeaderPush; /* multipart server push */
- #endif
-
- _GLOBAL_ long gHTTPHeaderOKSize;
- _GLOBAL_ long gHTTPHeaderRedirectSize;
- _GLOBAL_ long gHTTPHeaderErrSize;
- #if kCompileWithCGISendPartial
- _GLOBAL_ long gHTTPHeaderPushSize;
- #endif
-
- #undef _GLOBAL_
-
-
- /*** FUNCTION PROTOTYPES ***/
-
- OSErr InitCGIUtil ( void );
-
- #if kCompileWithCGIFormHandling
-
- p_export CGIFormField * CGIFormFieldsFromArgs ( char *, long *, short * );
- p_export CGIFormField * CGIFormFieldsFindRecord ( CGIHdl, const char * );
- p_export const char * CGIFormFieldsFindValue ( CGIHdl, const char * );
- void CGIFormFieldsDispose ( CGIFormField * );
-
- #endif /* kCompileWithCGIFormHandling */
-
- #if kCompileWithCGIActionSupport
- p_export Boolean CGIActionIsCGIorACGI ( CGIHdl );
- #endif
-
- p_export void CGIDecodeURLChars ( char * );
- p_export char * CGIEncodeURLChars ( const char *, OSErr * );
- p_export Boolean CGICharWillHex ( unsigned char );
- p_export void CGICharToHex ( unsigned char, char * );
-
- p_export void CGIPathToMacPath ( char * );
-
- pascal OSErr CGIAESearchDoc ( AppleEvent *, AppleEvent *, long );
-
- #if kCompileWithCGISendPartial
- p_export OSErr CGIAESendPartial ( CGIHdl, char *, long, Boolean );
- #endif /* kCompileWithCGISendPartial */
-
- p_export void CGILogData ( CGIHdl );
-
-
- /*** EXTERNAL FUNCTION PROTOTYPES ***/
-
- /* this is the function which you must define for your particular application */
- p_export void CustomCGIProcess ( CGIHdl );
-
- /* this function will be called after the cgi result has been returned.
- It will contain the same CGIHdl that was used for the CustomCGIProcess */
- p_export void CustomCGIPostProcess ( CGIHdl );
-
- /* this function is called once at startup time.
- Put any initialization you need to do in it. */
- p_export Boolean CustomCGIStartup ( void );
-
- /* this function is called at quitting time.
- Put any cleanup you need to do in it. */
- p_export Boolean CustomCGIQuit ( Boolean );
-
- #if !(kCompileWithout_MY_Names)
- #define MyCGIProcess CustomCGIProcess
- #define MyCGIStartup CustomCGIStartup
- #define MyCGIQuit CustomCGIQuit
- #endif
-
- #else /* if not kCompileWithCGICode */
-
- /* these are defined like this here so the StartupApplication function
- doesn't have to be messed with when compiling without the CGI module */
- #define InitCGIUtil() (noErr)
- #define CustomCGIStartup() (true)
- #define CustomCGIQuit() (true)
-
- #endif /* kCompileWithCGICode */
-
- /*** EOF ***/
-